import { call, put, fork, take } from 'redux-saga/effects'
import api from '@/api/enum'
import actions,{ 
  GET_SIGN_STATUS_ENUM, 
  GET_TEMPLATE_STATUS_ENUM,
  GET_INDUSTRY_ENUM,
  GET_SCENARIOS_ENUM,
  GET_OPERATOR_ENUM,
  GET_MESSAGE_STATUS_ENUM,
  GET_USER_RECHARGE_TYPE_ENUM,
  GET_AUDIT_BATCH_STATUS_ENUM,
} from '../actions/enum';
import signEditActions from '../actions/signEdit'

function* getSignStatusEnum() {
  try {
    const { isSuccess, data } = yield call(api.getSignStatusEnum)
    if(isSuccess) {
      yield put(actions.getSignStatusEnumSuccess(data))
    }
  } catch (error) {
    
  }
}

function* getTemplateStatusEnum() {
  try {
    const { isSuccess, data } = yield call(api.getTemplateStatusEnum)
    if(isSuccess) yield put(actions.getTemplateStatusEnumSuccess(data))
  } catch (error) {
    
  }
}

function* getIndustryEnum() {
  try {
    const { isSuccess, data } = yield call(api.getIndustryEnum)
    if(isSuccess){
      yield put(actions.getIndustryEnumSuccess(data))
    }
  } catch (error) {
    
  }
}

function* getScenariosEnum() {
  try {
    const { isSuccess, data } = yield call(api.getScenariosEnum)
    if(isSuccess){
      yield put(actions.getScenariosEnumSuccess(data))
    }
  } catch (error) {
    
  }
}

function* getOperatorEnum() {
  try {
    const { isSuccess, data } = yield call(api.getMsgOperatorEnum)
    if(isSuccess){
      yield put(actions.getOperatorEnumSuccess(data))
    } 
  } catch (error) {
    
  }
}

function* getMessageStatusEnum() {
  try {
    const { isSuccess, data } = yield call(api.getMsgSendStatusEnum)
    if(isSuccess){
      yield put(actions.getMessageStatusEnumSuccess(data))
    } 
  } catch (error) {
    
  }
}

function* getUserRechargeTypeEnum(){
  try {
    const { isSuccess, data } = yield call(api.getRechargeTypeEnum)
    if(isSuccess) yield put(actions.getUserRechargeTypeEnumSuccess(data))
  } catch (error) {
    
  }
}

function* getAuditBatchStatusEnum() {
  try {
    const { isSuccess, data } = yield call(api.getAuditBatchStatusEnum)
    if(isSuccess) yield put(actions.getAuditBatchStatusEnumSuccess(data)) 
  } catch (error) {
    
  }
}

function* watchGetAuditBatchStatusEnum(){
  while (true) {
    yield take(GET_AUDIT_BATCH_STATUS_ENUM)
    yield call(getAuditBatchStatusEnum)
  }
}

function* watchGetUserRechargeTypeEnum(){
  while (true) {
    yield take(GET_USER_RECHARGE_TYPE_ENUM)
    yield call(getUserRechargeTypeEnum)
  }
}

function* watchGetOperatorEnum() {
  while (true) {
    yield take(GET_OPERATOR_ENUM)
    yield call(getOperatorEnum)
  }
}

function* watchGetMessageStatusEnum() {
  while (true) {
    yield take(GET_MESSAGE_STATUS_ENUM)
    yield call(getMessageStatusEnum)
  }
}

function* watchGetIndustryEnum() {
  while (true) {
    yield take(GET_INDUSTRY_ENUM)
    yield call(getIndustryEnum)
  }
}

function* watchGetScenariosEnum() {
  while (true) {
    yield take(GET_SCENARIOS_ENUM)
    yield call(getScenariosEnum)
  }
}

function* watchGetSignStatusEnum() {
  while (true) {
    yield take(GET_SIGN_STATUS_ENUM)
    yield call(getSignStatusEnum)
  }
}

function* watchGetTemplateStatusEnum() {
  while (true) {
    yield take(GET_TEMPLATE_STATUS_ENUM)
    yield call(getTemplateStatusEnum)
  }
}

export default [
  fork(watchGetSignStatusEnum),
  fork(watchGetTemplateStatusEnum),
  fork(watchGetIndustryEnum),
  fork(watchGetScenariosEnum),
  fork(watchGetOperatorEnum),
  fork(watchGetMessageStatusEnum),
  fork(watchGetUserRechargeTypeEnum),
  fork(watchGetAuditBatchStatusEnum)
]